//
//  DownloadOperation.m
//  Example13-2
//
//  Created by 孙晓晔 on 2017/4/25.
//  Copyright © 2017年 孙晓晔. All rights reserved.
//

#import "DownloadOperation.h"
#import <UIKit/UIKit.h>

@implementation DownloadOperation

- (instancetype)initWithUrl:(NSString*)url {
    self = [super init];
    if (self) {
        self.strURL = url;
    }
    
    return self;
}

-(void)main {
    
    
    NSLog(@"线程 = %@, url = %@", [NSThread currentThread], self.strURL);
    
    NSURL *url =[NSURL URLWithString:self.strURL];
    
    NSData *data = [[NSData alloc] initWithContentsOfURL:url];
    
    UIImage *image = [[UIImage alloc]initWithData:data];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(didFinishDownloadImage:image:)]) {
        [self.delegate didFinishDownloadImage:self.strURL image:image];
    } else {
        if (self.block) {
            self.block(self.strURL, image);
        }
    }
}
@end
